<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/common/base.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="${ctsCss}/table.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<%@ include file="/common/message-save1.jsp" %>
<body>
	
	<form id="zongkong-form" class="form-horizontal" action="${ctx}/reportTemplateConditionsController/<c:choose><c:when test="${rptTemplateCondition.conditionId == null}">saveLie</c:when><c:otherwise>updateCondition</c:otherwise></c:choose>" method="post">
		<input type="hidden" name="templateId" value="${templateId}"/>
		<input type="hidden" name="conditionId" value="${rptTemplateCondition.conditionId}"/>
		<input type="hidden" name="conditionType" value="${rptTemplateCondition.conditionType}"/>
		<input type="hidden" id="setIdInput" name="setIdInput" value="${rptTemplateCondition.setId}"/>
		<input type="hidden" id="itemIdInput" name="itemIdInput" value="${rptTemplateCondition.itemId}"/>
		<table>
			 <tr class="tab_grey">
			      <td width="30%">列数：</td>
			      <td width="70%" colspan="3">
			      		<input type="text" id="colLetter" name="colLetter" value="${rptTemplateCondition.colLetter }" required  style="width:200px" maxlength='100' />
			      </td>
		     </tr>
		     <tr class="tab_grey">
			      <td width="30%">统计信息集：</td>
			      <td width="70%" colspan="3">
			      		<select id="dataSetSelect" name="setId" class="dataSetSelectClass" required onchange="loadDataItemList();"></select>
			      </td>
		     </tr>
		     <tr class="tab_grey">
			      <td width="30%">统计信息项：</td>
			      <td width="70%" colspan="3">
			      		<select id="dataItemSelect" name="itemId" class="dataItemSelectClass" required></select>
			      </td>
		     </tr>
		     <tr class="tab_grey">
			      <td width="30%">关系运算符：</td>
			      <td width="70%" colspan="3">
			      		<gdata:select items="${codedic['10010']}" id="relaOperator" name="relaOperator" cssClass="required" value="${rptTemplateCondition.relaOperator}" headerKey="请选择" cssStyle="width:150px"/>
			      </td>
		     </tr>
		     <tr class="tab_grey">
			      <td width="30%">条件值：</td>
			      <td width="70%" colspan="3">
			      		<input type="text" id="conditionVal" name="conditionVal" value="${rptTemplateCondition.conditionVal }" required  style="width:200px" maxlength='100' />
			      </td>
		     </tr>
		     <tr class="tab_grey">
			      <td width="30%">是否优先查询：</td>
			      <td width="70%" colspan="3">
			      		<gdata:select items="${codedic['10011']}" id="comboType" name="comboType" value="${rptTemplateCondition.comboType}" headerKey="请选择" cssStyle="width:150px"/>
			      </td>
		     </tr>
		     <tr class="tab_grey">
			      <td width="30%">并且/或者：</td>
			      <td width="70%" colspan="3">
			      		<gdata:select items="${codedic['10012']}" id="logicOperator" name="logicOperator" value="${rptTemplateCondition.logicOperator}" headerKey="请选择" cssStyle="width:150px"/>
			      </td>
		     </tr>
		     <tr class="tab_grey">
			      <td width="30%">序号</td>
			      <td width="70%" colspan="3">
			      		<input type="text" id="orderId" name="orderId" value="${rptTemplateCondition.orderId }" required  style="width:200px" maxlength='100' />
			      </td>
		     </tr>
		</table>
		<div  style="text-align: center;">
			<button type="button" class="btn btn-primary" id="saveBtn" onclick="categorySaveInfo();">保存</button>
		</div>
	</form>
	
</body>

<script type="text/javascript">
$('#zongkong-form').validate();

function categorySaveInfo(){
	$("#zongkong-form").submit();
}

$(document).ready(function(){
	loadDataSet();
});
//选择数据集后加载数据项
function loadDataItemList(){
	var setId = $("#dataSetSelect").val();
	var dataItemSelectId = $("#itemIdInput").val();
	$.ajax({
		url:'${ctx}/reportTemplateConditionsController/getAllDataItemBySetId/' + setId,
		type:'POST',
		cache:false,
		success:function(data){
			var dataItemOptions = "";
		    $.each(data,function(idx,item){
		    	if(item.id==dataItemSelectId){
		    		dataItemOptions += "<option value='" + item.id + "' selected>" + item.itemChineseName + "</option>";
		    	}else{
		    		dataItemOptions += "<option value='" + item.id + "'>" + item.itemChineseName + "</option>";
		    	}
			});
		    $("#dataItemSelect option").remove();
		    dataItemOptionsFirst="<option value=''>请选择</option>";
		    $(".dataItemSelectClass").append(dataItemOptionsFirst).append(dataItemOptions);
		}
	});
}

//加载数据集
function loadDataSet(){
	var dataSetSelectId = $("#setIdInput").val();
	var dataItemSelectId = $("#itemIdInput").val();
	$.ajax({
		url:'${ctx}/reportTemplateConditionsController/getAllDataSet',
		type:'POST',
		cache:false,
		success:function(data){
			var dataSetOptions = "";
		    $.each(data,function(idx,item){
		    	if(dataSetSelectId == item.id){
		    		dataSetOptions += "<option value='" + item.id + "' selected>" + item.chineseName + "</option>";
		    	}else{
		    		dataSetOptions += "<option value='" + item.id + "'>" + item.chineseName + "</option>";
		    	}
			});
		    $("#dataSetSelect option").remove();
		    dataSetOptionsFirst="<option value=''>请选择</option>";
		    $(".dataSetSelectClass").append(dataSetOptionsFirst).append(dataSetOptions);
		    if(dataSetSelectId != null && dataItemSelectId != null){
		    	loadDataItemList();
		    }
		}
	});
}

</script>
</html>